package com.qf.service.impl;

import com.qf.pojo.Order;
import com.qf.service.OrderService;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Value;

import java.util.ArrayList;
import java.util.List;


/*
    这个注解导包是，一定要导入apache的包名,千万不要导成spring的service
    ① 向当前应用的spring容器中添加一个OrderService对象
    ② 将当前这个接口的信息整合成一个URL，并将URL暴露出去。（将url写出到zookeeper中保存）
       [dubbo%3A%2F%2F192.168.247.1%3A20880%2Fcom.qf.service.OrderService%3Fanyhost%3Dtrue%26application%3
       Ddubbo-order%26bean.name%3DServiceBean%3Acom.qf.service.OrderService%26deprecated%3Dfalse%26
       dubbo%3D2.0.2%26dynamic%3Dtrue%26generic%3Dfalse%26interface%3Dcom.qf.service.OrderService%26
       methods%3DfindByUid%26pid%3D14180%26register%3Dtrue%26release%3D2.7.3%26
       side%3Dprovider%26timestamp%3D1668395929997]
       基于配置的协议和端口启动一个内置的服务。比如我们这里配置的是dubbo:20880.在当前应用内启动一个netty服务 （相当于网络编程中写的ServerSocket -- Socket）
        这个netty服务的功能是用来接收远程消费者调用的。
 */
@Service(version = "1.0")
public class OrderServiceImpl implements OrderService {

    @Value("${server.port}")
    private Integer port;

    @Override
    public List<Order> findByUid(Integer uid) throws InterruptedException {

        System.out.println("订单查询开始.....");

        if (port == 82) {
            Thread.sleep(5000);
        }

        //根据用户id，数据库查询用户的订单信息
        Order order1 = new Order(1,uid,1000d,"用户丁1"+port);
        Order order2 = new Order(2,uid,2000d,"用户丁2"+port);
        Order order3 = new Order(3,uid,3000d,"用户丁3"+port);

        List<Order> orders = new ArrayList<>();
        orders.add(order1);
        orders.add(order2);
        orders.add(order3);

        System.out.println("订单查询结束.....");

        return orders;
    }
}
